<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    .container {
      position: relative;
      margin: 100px auto auto;
      width: 600px;
      height: 600px;
      background-color: blanchedalmond;
      cursor: pointer;
    }
    .ball {
      position: absolute;
      left: 100px;
      top: 100px;
      width: 60px;
      height: 60px;
      border-radius: 50%;
      background-color: red;
    }
  </style>
</head>
<body>
  <div id="app">
    <div class="container" @mousemove.stop="move">
      <div class="ball" :style="{left: offsetX + 'px', top: offsetY + 'px'}"></div>
    </div>
  </div>
  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
  <script>
    const App = {
      data() {
        return {
          offsetX: 0,
          offsetY: 0,
          containerClientX: 0,
          ballHalfWidth: 0
        }
      },
      methods: {
        move(e) {
          console.log(e)
          const { clientX, clientY } = e
          console.log(clientX, this.containerClientX, this.ballHalfWidth)
          // this.offsetX = clientX - this.containerClientX -  this.ballHalfWidth
          // this.offsetY = clientY - this.containerClientX - this.ballHalfWidth
        },
        getContainerClientX() {
          const el = document.querySelector('.container')
          this.containerClientX = el.getBoundingClientRect().left
        },
        getBallHalfWidth() {
          const el = document.querySelector('.ball')
          let width = window.getComputedStyle(el).width
          this.ballHalfWidth = Math.floor(parseInt(width) / 2)
        }
      },
      mounted() {
        this.getBallHalfWidth()
        this.getContainerClientX()
      }
    }
    Vue.createApp(App).mount('#app')
  </script>
</body>
</html>